package com.kk.network.httpclient;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 进行文件合并操作
 * 
 * @author liujun
 * @date 2018/07/20
 */
public class FileMarge {

	/**
	 * 实例化对象信息
	 */
	public static final FileMarge INSTANCE = new FileMarge();

	/**
	 * 进行文的拷贝追加文件操作
	 * 
	 * @param input  输入文件
	 * @param output 追加输出文件
	 */
	public void fileCopyAppend(String input, String output) {
		FileInputStream inputStream = null;
		FileOutputStream outputStream = null;
		byte[] buffer = new byte[512];
		try {
			inputStream = new FileInputStream(input);
			outputStream = new FileOutputStream(output, true);

			int index = 0;
			while ((index = inputStream.read(buffer)) != -1) {
				outputStream.write(buffer, 0, index);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (null != outputStream) {
				try {
					outputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (null != inputStream) {
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
